const pkg = require('./package')
const path = require('path')
const SpritesmithPlugin = require('webpack-spritesmith')
module.exports = {
  mode: 'spa',

  /*
  ** Headers of the page
  */
  head: {
    title: pkg.description,
    meta: [
      { charset: 'utf-8' },
      /** 360浏览器中使用wenkit内核**/
      { name: 'renderer', content: 'webkit|ie-comp|ie-stand' },
      { 'http-equiv': 'X-UA-Compatible', content: 'IE=edge,chrome=1' },
      {
        name: 'viewport',
        content:
          'width=device-width,inital-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no'
      },
      { hid: 'description', name: 'description', content: 'crm system' },
      { name: 'apple-mobile-web-app-status-bar-style', content: 'black' },
      { name: 'format-detection', content: 'telephone=yes, email=yes' },
      { name: 'apple-mobile-web-app-capable', content: 'yes' },
      { name: 'full-screen', content: 'yes' }
    ],
    link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
    script: [
      { src: '//api.map.baidu.com/api?v=2.0&ak=eGWUBI70w1GCDWCZljnPwLG91bOBZXC5' }
    ]
  },

  /**
   * Customize the progress bar color
   */
  loading: { color: '#5bc3bb' },

  /**
   * When running nuxt.js in SPA mode, there is no content from the server side on the first page load, So instead of showing a blank page while the page loads, we may show a spinner.
   */
  loadingIndicator: 'wandering-cubes',

  /**
   * Nuxt.js lets you define the CSS files/modules/libraries you want to set globally (included in every page).
   */
  css: [
    'normalize.css',
    'element-ui/lib/theme-chalk/index.css',
    '~/assets/sass/index.scss'
  ],

  /*
  ** Plugins to load before mounting the App
  */
  plugins: ['~plugins/element-ui', '~plugins/helper', '~api/app', '~plugins/Viewer'],

  /*
  ** Nuxt.js modules
  */
  modules: ['@nuxtjs/axios'],
  /*
   ** retry 重试  retries 的次数
   */
  axios: {
    retry: { retries: 3 },
    baseURL: process.env.SITE_ENV === 'prod' ? 'http://api.maryya.com' : 'http://qa.api.maryya.freeradio.cn'
    // proxyHeaders: false
  },

  /*
  ** Build configuration
  */
  build: {
    publicPath: '/static/',
    extractCSS: true,
    /*
    ** Run ESLint on save
    */
    extend (config, { isDev, isClient }) {
      if (isDev && isClient) {
        config.module.rules.push(
          {
            enforce: 'pre',
            test: /\.(js|vue)$/,
            loader: 'eslint-loader',
            exclude: /(node_modules)/
          },
          {
            test: /\.styl(us)?$/,
            loader: 'stylus-loader',
            exclude: /(node_modules)/,
            options: {
              'resolve url': true
            }
          }
        )
      }
    },
    plugins: [
      // new SpritesmithPlugin({
      //   src: {
      //     // 设置源icons,即icon的路径，必选项
      //     cwd: path.resolve(__dirname, 'assets/ico'),
      //     glob: '*.png'
      //   },
      //   target: {
      //     // 设置导出的sprite图及对应的样式文件，必选项
      //     image: path.resolve(__dirname, 'assets/img/sprite.png'),
      //     css: path.resolve(__dirname, 'assets/sass/sprite.scss')
      //   },
      //   apiOptions: {
      //     // //设置sprite.png的引用格式
      //     cssImageRef: '~assets/img/sprite.png' // cssImageRef为必选项
      //   }
      // })
    ]
  },
  router: {
    // middleware: ''
    // linkActiveClass: "active"
  },
  generate: {
    dir: process.env.SITE_ENV === 'prod' ? 'dist/prod' : (process.env.SITE_ENV === 'qa' ? 'dist/qa' : 'dist/dev')
  }

}
